﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Xml;
using BusinessLogic.ClassFactory;
using Common;
using Model.Data;
using UtilCommon;
using DataCach;

namespace BusinessLogic.BusinessRules
{
    /// <summary>
    /// Article 的摘要说明。
    /// </summary>
    public class Article : BaseClass
    {
        #region 必有属性

        private SessionUser _sessionUser;

        public SessionUser SessionUser
        {
            get { return _sessionUser; }
            set { _sessionUser = value; }
        }

        private string _strParentPath = "";

        public string ParentPath
        {
            get { return _strParentPath; }
            set { _strParentPath = value; }
        }

        private string _strPageName = "";

        public string PageName
        {
            get { return _strPageName; }
            set { _strPageName = value; }
        }


        public Model.Data.ArticleData.ArticleRow DataItem
        {
            get
            {
                return (Model.Data.ArticleData.ArticleRow)base.m_CurrentRow;
            }
            set
            {
                base.m_CurrentRow = value;
            }
        }

        private Model.Data.ArticleData m_Data
        {
            get
            {
                return (Model.Data.ArticleData)base.m_DataSet;
            }
            set
            {
                base.m_DataSet = value;
            }
        }

        public override int Count
        {
            get
            {
                return this.m_Data.Article.Count;
            }
        }

        #endregion 必有属性

        #region 构造函数

        public Article(DataAccess.DBManager m_DBManager, DataAccess.BaseAccess m_Access)
            : base(m_DBManager, m_Access)
        {
        }

        #endregion 构造函数

        #region 必须重载方法

        /// <summary>
        /// 根据数据集中索引,设置当前数据行
        /// </summary>
        /// <param name="n_index">数据集中的索引</param>
        public override void SelectRow(int n_index)
        {
            if (m_Data != null && m_Data.Article.Rows.Count > n_index)
            {
                DataItem = m_Data.Article[n_index];
            }
        }

        /// <summary>
        /// 实现更新
        /// </summary>
        /// <returns></returns>
        protected override int OnUpdate()
        {
            return m_Access.Update(this.m_DataSet);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        protected override bool OnDelete(int ID)
        {
            return true;
        }

        public override void NewDataSet()
        {
            this.m_Data = new ArticleData();
            m_CurrentRow = m_Data.Article.NewArticleRow();
        }

        public override void SetDataSet(DataSet m_DataSet)
        {
            this.m_DataSet = m_DataSet;
        }

        public override bool OnInsert()
        {
            this.DataItem.intArticleID = this.GetNextSeed();
            this.m_Data.Article.Rows.Add(this.m_CurrentRow);
            return true;
        }

        #endregion 必须重载方法

        #region 业务属性

        public Model.Data.ArticleData Data
        {
            get
            {
                return (Model.Data.ArticleData)base.m_DataSet;
            }
            set
            {
                base.m_DataSet = value;
            }
        }

        private string[] strArrayBuild()
        {
            try
            {
                List<string> lstcolumnBuilder = new List<string>();
                string tblName = this.GetType().Name;
                string strPrimaryKey = this.Data.Article.DataSet.Tables[0].PrimaryKey[0].ColumnName;
                System.Data.DataTable schemaTable = this.m_DBManger.CurrentlyConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, new object[] { null, null, tblName, null });

                lstcolumnBuilder.Add("ArtSecRelation.intSecArtID");
                lstcolumnBuilder.Add("ArtSecRelation.intSectionID");
                lstcolumnBuilder.Add("ArtSecRelation.intAccessCount");
                lstcolumnBuilder.Add("ArtSecRelation.intSectionRec");
                lstcolumnBuilder.Add("ArtSecRelation.intGlobalRec");
                lstcolumnBuilder.Add("ArtSecRelation.intSectionTop");
                lstcolumnBuilder.Add("ArtSecRelation.intGlobalTop");
                lstcolumnBuilder.Add("Sections.chvSTCName");
                lstcolumnBuilder.Add("Sections.chvSTEName");
                lstcolumnBuilder.Add("Sections.chvParentPath");
                lstcolumnBuilder.Add("Sections.chvPageName");

                //获取到列名称
                foreach (DataRow row in schemaTable.Rows)
                {
                    if (row["column_name"].ToString() != strPrimaryKey)
                    {
                        lstcolumnBuilder.Add(tblName + "." + row["column_name"].ToString());
                    }
                }
                return lstcolumnBuilder.ToArray();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private string GetArticleIssueFile
        {
            get
            {
                object objFinallyBuild = DataCach.SetCachecs.SetCache.GetCache(Common.ValueConfig.CatchNameArticleColume);
                if (objFinallyBuild != null)
                {
                    return objFinallyBuild.ToString(); ;
                }
                else
                {
                    StringBuilder strSqlSegment = new StringBuilder();//自定义sql片段
                    string[] aryFields = strArrayBuild();
                    strSqlSegment.Append("Select ");
                    for (int i = 0; i < aryFields.Length; i++)
                    {
                        if (i == aryFields.Length - 1)
                        {
                            strSqlSegment.Append(aryFields[i] + "  ");
                        }
                        else
                        {
                            strSqlSegment.Append(aryFields[i] + ",");
                        }
                    }
                    strSqlSegment.Append(" From [Article],[ArtSecRelation],[Sections] Where ArtSecRelation.intArticleId=Article.intArticleId  and ArtSecRelation.intSectionID=Sections.intSectionID  and ArtSecRelation.intSecArtID =");
                    DataCach.SetCachecs.SetCache.Insert(Common.ValueConfig.CatchNameArticleColume, strSqlSegment.ToString(), 3600);
                    return strSqlSegment.ToString();
                }
            }
        }

        /// <summary>
        ///
        /// </summary>
        private string GetArticleIssueNoContentFile
        {
            get
            {
                StringBuilder strSqlSegment = new StringBuilder();//自定义sql片段
                string[] aryFields = strArrayBuild();
                strSqlSegment.Append("Select ");
                for (int i = 0; i < aryFields.Length; i++)
                {
                    if (i == aryFields.Length - 1)
                    {
                        strSqlSegment.Append(aryFields[i] + "  ");
                    }
                    else
                    {
                        strSqlSegment.Append(aryFields[i] + ",");
                    }
                }
                strSqlSegment.Append(" From [Article],[ArtSecRelation],[Sections] Where ArtSecRelation.intArticleId=Article.intArticleId  and ArtSecRelation.intSectionID=Sections.intSectionID and  ArtSecRelation.intSecArtID in");
                return strSqlSegment.ToString();
            }
        }

        #endregion 业务属性

        //发布文章字段，处理type=4的插件
        public string GetArticleHavecontentXml(int intSTID, int intArtSecID, SessionUser objSessionUser)
        {
            SessionUser = objSessionUser;
            string strSql = GetArticleIssueFile + intArtSecID;
            DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);

            if (tblTmp.Rows.Count == 0)
            {
                return Common.Xml.XmlHelper.GetNewXMLDoc();
            }
            // 将某些字段属性值进行修改
            DataRow row = tblTmp.Rows[0];

            //// 修改文章图片链接
            //if (int.Parse(row["intType"].ToString()) == 3)//flash
            //{
            //    StringBuilder strContent = new StringBuilder();
            //    strContent.AppendFormat("<OBJECT classid=\"clsid: D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH=\"{0}\" HEIGHT=\"550\">", System.Configuration.ConfigurationSettings.AppSettings["strFlashWidth"].ToString());
            //    strContent.AppendFormat("<PARAM NAME=\"movie\" VALUE={0}>", SystemVariable.WebUrl + "Pictures/" + row["txtContent"].ToString());
            //    strContent.Append("<param name=\"wmode\" value=\"transparent\">");
            //    strContent.Append("<PARAM NAME=\"quality\" VALUE=\"transparent\">");
            //    strContent.Append("<PARAM NAME=\"bgcolor\" VALUE=\"#E0F8E2\">");
            //    strContent.AppendFormat("<EMBED wmode=\"transparent\" src={0} quality=\"high\" bgcolor=\"#E0F8E2\" WIDTH=\"{1}\" HEIGHT=\"550\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>",
            //        SystemVariable.WebUrl + "Pictures/" + row["txtContent"].ToString(),
            //        System.Configuration.ConfigurationSettings.AppSettings["strFlashWidth"].ToString());
            //    row["txtContent"] = strContent.ToString();
            //}

            //if (int.Parse(row["intType"].ToString()) == 4)
            //{
            //    StringBuilder strContent = new StringBuilder();
            //    strContent.Append("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"490\" height=\"430\"> ");
            //    strContent.AppendFormat("<param name=\"movie\" value=\"Flvplayer.swf\" /> <param name=\"quality\" value=\"high\" /> <param name=\"wmode\" value=\"opaque\" /> <param name=\"allowFullScreen\" value=\"true\" /> ");
            //    strContent.AppendFormat("<param name='FlashVars' value='vcastr_file={0}' /> ", SystemVariable.WebUrl + "Pictures/" + row["txtContent"].ToString());
            //    strContent.AppendFormat("<embed src='Flvplayer.swf' allowfullscreen='true' flashvars='vcastr_file={0}'  quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='100%' height='100%'></embed></object>", SystemVariable.WebUrl + "Pictures/" + row["txtContent"].ToString());
            //    row["txtContent"] = strContent.ToString();
            //}

            #region 生成XML

            StringBuilder sbXML = new StringBuilder();
            XmlTextWriter objWriter = new XmlTextWriter(new System.IO.StringWriter(sbXML));
            try
            {
                objWriter.WriteStartDocument();
                objWriter.WriteStartElement("TMPL");
                objWriter.WriteStartElement("Article");
                if (row["chvMainPic"] != DBNull.Value)
                {
                    if (SessionUser.EnableParentPath)
                    {
                        row["chvMainPic"] = "/news/" + SessionUser.VartualPath + "/Pcfiles/" + row["chvMainPic"].ToString();
                    }
                    else
                    {
                        row["chvMainPic"] = "../Pcfiles/" + row["chvMainPic"].ToString();
                    }
                }
                else
                {
                    if (SessionUser.EnableParentPath)
                    {
                        row["chvMainPic"] = "/news/" + SessionUser.VartualPath + "/Pcfiles/Default.jpg";
                    }
                    else
                    {
                        row["chvMainPic"] = "../Pcfiles/Default.jpg";
                    }
                }
                // 修改文章附件链接
                if (row["chvFilePath"] != DBNull.Value)
                {
                    if (row["chvFilePath"].ToString().Trim() != "")
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            row["chvFilePath"] = "/news/" + SessionUser.VartualPath + "/Pcfiles/" + row["chvFilePath"].ToString();
                        }
                        else
                        {
                            row["chvFilePath"] = "../Pcfiles/Files/" + row["chvFilePath"].ToString();
                        }
                    }
                }
                // 修改文章视频链接
                if (row["chvVedioPath"] != DBNull.Value)
                {
                    if (row["chvVedioPath"].ToString().Trim() != "")
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            row["chvVedioPath"] = "/news/" + SessionUser.VartualPath + "/Pcfiles/Files/" + row["chvVedioPath"].ToString();
                        }
                        else
                        {
                            row["chvVedioPath"] = "../Pcfiles/Files/" + row["chvVedioPath"].ToString();
                        }
                    }
                }

                // 添加数据库字段值
                for (int i = 0; i < tblTmp.Columns.Count; i++)
                {
                    if (row[i] != DBNull.Value)
                    {
                        if (tblTmp.Columns[i].ColumnName == "dtmInTime")
                        {
                            DateTime dtmInDate = DateTime.Parse(row["dtmInTime"].ToString());
                            objWriter.WriteStartElement(tblTmp.Columns[i].ColumnName);
                            objWriter.WriteAttributeString("year", dtmInDate.Year.ToString("000#"));
                            objWriter.WriteAttributeString("month", dtmInDate.Month.ToString("0#"));
                            objWriter.WriteAttributeString("day", dtmInDate.Day.ToString("0#"));
                            objWriter.WriteAttributeString("hh", dtmInDate.Hour.ToString("0#"));
                            objWriter.WriteAttributeString("mm", dtmInDate.Minute.ToString("0#"));
                            objWriter.WriteCData(dtmInDate.ToString("yyyy年MM月dd日"));
                            objWriter.WriteEndElement();
                        }
                        else
                        {
                            //构建扩展字段
                            if (tblTmp.Columns[i].ColumnName == "txtExpand")
                            {
                                if (row["txtExpand"] != DBNull.Value)
                                {
                                    string strXml = row["txtExpand"].ToString();
                                    if (!strXml.Trim().Equals(""))
                                    {
                                        StringBuilder objbuilder = new StringBuilder();
                                        try
                                        {
                                            XmlDocument strXML = new XmlDocument();
                                            strXML.LoadXml(strXml);
                                            XmlNode objExtenRootNode = strXML.SelectSingleNode("/datamodel");
                                            if (objExtenRootNode != null)
                                            {
                                                if (objExtenRootNode.HasChildNodes)
                                                {
                                                    objWriter.WriteString(objExtenRootNode.InnerXml);
                                                    XmlNodeList objXMLNOdeList = objExtenRootNode.ChildNodes;
                                                    foreach (XmlNode objNodeTemp in objXMLNOdeList)
                                                    {
                                                        objWriter.WriteStartElement(objNodeTemp.Name);
                                                        objWriter.WriteCData(objNodeTemp.InnerText);
                                                        objWriter.WriteEndElement();
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            throw new Exception("构建文章xml时扩展的结构存在问题，不符合格式。" + ex.Message.Replace("\r\n", ""));
                                        }
                                    }
                                }
                                objWriter.WriteStartElement("chvNoHtmlSummary");
                                objWriter.WriteCData(ClearKeyWord.ClearHTML(row[i].ToString()));
                                objWriter.WriteEndElement();
                            }
                            else
                            {
                                objWriter.WriteStartElement(tblTmp.Columns[i].ColumnName);
                                objWriter.WriteCData(row[i].ToString());
                                objWriter.WriteEndElement();
                            }
                        }

                        //构建没有html字符的文章简介
                        if (tblTmp.Columns[i].ColumnName == "chvSummary")
                        {
                            objWriter.WriteStartElement("chvNoHtmlSummary");
                            objWriter.WriteCData(ClearKeyWord.ClearHTML(row[i].ToString()));
                            objWriter.WriteEndElement();
                        }
                    }
                }
                // 文章当前位置
                SectionsFactory objFactory = new SectionsFactory(this.m_DBManger);

                Sections objSection = objFactory.Creator(intSTID);
                objSection.SessionUser = objSessionUser;
                objSection.GetCurPosXml(objWriter, false);

                objWriter.WriteEndElement();
                objWriter.WriteEndElement();
                objWriter.WriteEndDocument();

                objWriter.Flush();
            }
            finally
            {
                objWriter.Close();
            }

            #endregion 生成XML

            return sbXML.ToString();
        }

        ///// <summary>
        ///// 设置文章发布状态为已发布
        ///// </summary>
        ///// <param name="intSTID">栏目ID</param>
        ///// <param name="IsIssue">是否已发布</param>
        //public void SetArticleIssueStatus(int intSTID, bool IsIssue)
        //{
        //    if (IsIssue)
        //    {
        //        SectionsFactory objFactory = new SectionsFactory(m_DBManger);
        //        objFactory.UpdateState(intSTID);
        //    }
        //}

        /// <summary>
        /// 获取多篇文章的XML数据
        /// </summary>
        /// <param name="intSTID">栏目ID</param>
        /// <param name="objWriter"></param>
        /// <param name="aryArticleIDs">多篇文章的ID数组</param>
        /// <param name="strSectionRealUrl">栏目的真实URL：暂时没有用处</param>
        public void GetManyArticlesNoContentXml(XmlTextWriter objWriter, ArrayList aryArticleIDs, bool bolShowInIndex, bool bolSectiuonIsRefer, int intSectionID,bool bolFilterCurrentArticle, int intArtSecID)
        {
            if (aryArticleIDs == null)
            {
                return;
            }
            string strIDs = "(";
            for (int i = 0; i < aryArticleIDs.Count; i++)
            {
                strIDs += string.Format("{0}, ", aryArticleIDs[i]);
            }
            strIDs += "-1000)";		// 添加一个不存在的ArticleID,以便组成格式(1,2,3,)

            string strSql = GetArticleIssueNoContentFile + strIDs + " order by Article.dtmInTime";
            DataTable tblTmp = this.m_Access.ExecuteDataTable(strSql);

            //必须按照aryArticleIDs的顺序来组织
            for (int x = 0; x < aryArticleIDs.Count; x++)
            {
                // 将某些字段属性值进行修改
                string strFilter = string.Format("intSecArtID = {0}", aryArticleIDs[x]);
                if (tblTmp.Select(strFilter).Length > 0)
                {
                    DataRow row = tblTmp.Select(strFilter)[0];

                    // 修改文章图片链接
                    if (row["chvMainPic"] != DBNull.Value)
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            row["chvMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/" + row["chvMainPic"].ToString();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                row["chvMainPic"] = "Pcfiles/" + row["chvMainPic"].ToString();
                            }
                            else
                            {
                                row["chvMainPic"] = "../Pcfiles/" + row["chvMainPic"].ToString();
                            }
                        }
                    }
                    else
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            row["chvMainPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/Default.jpg";
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                row["chvMainPic"] = "Pcfiles/Default.jpg";
                            }
                            else
                            {
                                row["chvMainPic"] = "../Pcfiles/Default.jpg";
                            }
                        }
                    }
                    // 修改文章缩略图片链接
                    if (row["chvMainMiniPic"] != DBNull.Value)
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            row["chvMainMiniPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/" + row["chvMainMiniPic"].ToString();
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                row["chvMainMiniPic"] = "Pcfiles/" + row["chvMainMiniPic"].ToString();
                            }
                            else
                            {
                                row["chvMainMiniPic"] = "../Pcfiles/" + row["chvMainMiniPic"].ToString();
                            }
                        }
                    }
                    else
                    {
                        if (SessionUser.EnableParentPath)
                        {
                            row["chvMainMiniPic"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/Default.jpg";
                        }
                        else
                        {
                            if (bolShowInIndex == true)
                            {
                                row["chvMainMiniPic"] = "Pcfiles/Default.jpg";
                            }
                            else
                            {
                                row["chvMainMiniPic"] = "../Pcfiles/Default.jpg";
                            }
                        }
                    }
                    // 修改文章附件链接
                    if (row["chvFilePath"] != DBNull.Value)
                    {
                        if (row["chvFilePath"].ToString().Trim() != "")
                        {
                            if (SessionUser.EnableParentPath)
                            {
                                row["chvFilePath"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/Files/" + row["chvFilePath"].ToString();
                            }
                            else
                            {
                                if (bolShowInIndex == true)
                                {
                                    row["chvFilePath"] = "Pcfiles/Files/" + row["chvFilePath"].ToString();
                                }
                                else
                                {
                                    row["chvFilePath"] = "../Pcfiles/Files/" + row["chvFilePath"].ToString();
                                }
                            }
                        }
                    }
                    // 修改文章视频链接
                    if (row["chvVedioPath"] != DBNull.Value)
                    {
                        if (row["chvVedioPath"].ToString().Trim() != "")
                        {
                            if (SessionUser.EnableParentPath)
                            {
                                row["chvVedioPath"] = "/news/" + this.SessionUser.VartualPath + "/Pcfiles/Files/" + row["chvVedioPath"].ToString();
                            }
                            else
                            {
                                if (bolShowInIndex == true)
                                {
                                    row["chvVedioPath"] = "Pcfiles/Files/" + row["chvVedioPath"].ToString();
                                }
                                else
                                {
                                    row["chvVedioPath"] = "../Pcfiles/Files/" + row["chvVedioPath"].ToString();
                                }
                            }
                        }
                    }
                    //检测文章父栏目链接
                    if (bolSectiuonIsRefer)
                    {
                        if (row["intSectionID"] != DBNull.Value)
                        {
                            if (row["intSectionID"].ToString().Trim() != "")
                            {
                                row["intSectionID"] = intSectionID;
                            }
                        }
                    }

                    #region 生成XML

                    objWriter.WriteStartElement("Article");

                    // 添加数据库字段值
                    for (int i = 0; i < tblTmp.Columns.Count; i++)
                    {
                        if (row[i] != DBNull.Value)
                        {
                            // 文章录入时间
                            if (tblTmp.Columns[i].ColumnName == "dtmInTime")
                            {
                                DateTime dtmInDate = DateTime.Parse(row["dtmInTime"].ToString());
                                objWriter.WriteStartElement(tblTmp.Columns[i].ColumnName);
                                objWriter.WriteAttributeString("year", dtmInDate.Year.ToString("000#"));
                                objWriter.WriteAttributeString("month", dtmInDate.Month.ToString("0#"));
                                objWriter.WriteAttributeString("day", dtmInDate.Day.ToString("0#"));
                                objWriter.WriteCData(dtmInDate.ToString("yyyy年MM月dd日"));
                                objWriter.WriteEndElement();
                            }
                            // 文章标题
                            else if (tblTmp.Columns[i].ColumnName == "chvTitle")
                            {
                                string strDisplayTitle = string.Empty; // 不含html格式的完整的标题
                                string strColor = string.Empty;		// 标题颜色
                                string strStyle = string.Empty;		// 标题样式
                                string strSize = string.Empty;		// 标题字体大小
                                strDisplayTitle = row["chvTitle"].ToString();
                                objWriter.WriteStartElement(tblTmp.Columns[i].ColumnName);

                                objWriter.WriteCData(strDisplayTitle);
                                objWriter.WriteEndElement();
                            }
                            else
                            {
                                //构建没有html字符的文章简介
                                if (tblTmp.Columns[i].ColumnName == "txtExpand")
                                {
                                    if (row["txtExpand"] != DBNull.Value)
                                    {
                                        string strXml = row["txtExpand"].ToString();
                                        if (!strXml.Trim().Equals(""))
                                        {
                                            StringBuilder objbuilder = new StringBuilder();
                                            try
                                            {
                                                XmlDocument strXML = new XmlDocument();
                                                strXML.LoadXml(strXml);
                                                XmlNode objExtenRootNode = strXML.SelectSingleNode("/datamodel");
                                                if (objExtenRootNode != null)
                                                {
                                                    if (objExtenRootNode.HasChildNodes)
                                                    {
                                                        if (objExtenRootNode.HasChildNodes)
                                                        {
                                                            XmlNodeList objXMLNOdeList = objExtenRootNode.ChildNodes;
                                                            foreach (XmlNode objNodeTemp in objXMLNOdeList)
                                                            {
                                                                objWriter.WriteStartElement(objNodeTemp.Name);
                                                                objWriter.WriteCData(objNodeTemp.InnerText);
                                                                objWriter.WriteEndElement();
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                                throw new Exception("构建文章xml时扩展的结构存在问题，不符合格式。" + ex.Message.Replace("\r\n", ""));
                                            }
                                        }
                                    }
                                    objWriter.WriteStartElement("chvNoHtmlSummary");
                                    objWriter.WriteCData(ClearKeyWord.ClearHTML(row[i].ToString()));
                                    objWriter.WriteEndElement();
                                }
                                else
                                {
                                    objWriter.WriteStartElement(tblTmp.Columns[i].ColumnName);
                                    objWriter.WriteCData(row[i].ToString());
                                    objWriter.WriteEndElement();
                                }
                            }
                            //构建没有html字符的文章简介
                            if (tblTmp.Columns[i].ColumnName == "chvSummary")
                            {
                                objWriter.WriteStartElement("chvNoHtmlSummary");
                                objWriter.WriteCData(ClearKeyWord.ClearHTML(row[i].ToString()));
                                objWriter.WriteEndElement();
                            }
                            //构建是否当前文章
                            if (tblTmp.Columns[i].ColumnName == "intSecArtID")
                            {
                                int intCurASID = Convert.ToInt32(row[i].ToString());
                                objWriter.WriteStartElement("current");
                                objWriter.WriteCData(intCurASID==intArtSecID?"1":"0");
                                objWriter.WriteEndElement();
                            }
                        }
                    }
                    //objWriter.WriteCData(System.Web.HttpContext.Current.Request.Path.Replace("ServerPages/Issue/Issue.aspx", "") + "Pcfiles/Default.jpg");

                    //文章所在栏目链接
                    string strSectionUrl = "";
                    string strSectionPath = "";
                    string strSectionName = "";

                    // 文章URL
                    string strArticleUrl = string.Empty;
                    if (SessionUser.EnableParentPath)
                    {
                        string strPath = "";
                        string strName = "";

                        if (row["chvParentPath"] == DBNull.Value)
                        {
                            this.ParentPath = "";
                        }
                        else
                        {
                            this.ParentPath = row["chvParentPath"].ToString().Trim();
                        }

                        if (row["chvPageName"] == DBNull.Value)
                        {
                            this.PageName = "";
                        }
                        else
                        {
                            this.PageName = row["chvPageName"].ToString().Trim();
                        }
                        //路径为空白，则发布到shtml文件夹下，"/"代表发布到根目录下,其他文本则发布到嘴硬的文件夹下
                        if (this.ParentPath == "" && this.PageName == "")
                        {
                            strPath = "ahtml/";
                            strSectionPath = "shtml/";
                            strName = "A__" + (bolSectiuonIsRefer ? intSectionID + "_" : "") + row["intSecArtID"].ToString();
                            strSectionName = "T-" + row["intSectionID"].ToString();
                        }
                        else
                        {
                            strPath = this.ParentPath == "" ? "shtml/" : (this.ParentPath == "/" ? "" : this.ParentPath + "/");
                            strSectionPath = this.ParentPath == "" ? "shtml/" : (this.ParentPath=="/"?"":this.ParentPath + "/");
                            strName = this.PageName + "_A__" + (bolSectiuonIsRefer ? intSectionID + "_" : "") + row["intSecArtID"].ToString();
                            strSectionName = this.PageName==""? ("T-" + row["intSectionID"].ToString()): this.PageName;
                        }
                        if (SessionUser.WebSiteLevel != 1)
                        {
                            strPath = SessionUser.VartualPath + "/" + strPath;
                        }

                        strSectionUrl = "/" + strPath + strSectionName + "." + Common.AppConfig.GetWebFileType();
                        if (this.SessionUser.EnableShortPath)
                        {
                            strSectionUrl = strSectionUrl.ToLower().Replace("default.htm", "");
                        }
                        strArticleUrl = "/" + strPath + strName+ "." + Common.AppConfig.GetWebFileType();
                    }
                    else
                    {
                        if (bolShowInIndex == true)
                        {
                            strArticleUrl = "ahtml/A__" + (bolSectiuonIsRefer ? intSectionID + "_" : "") + row["intSecArtID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                        }
                        else
                        {
                            strArticleUrl = "../ahtml/A__" + (bolSectiuonIsRefer ? intSectionID + "_" : "") + row["intSecArtID"].ToString() + "." + Common.AppConfig.GetWebFileType();
                        }
                    }

                    objWriter.WriteStartElement("chvFullPath");
                    objWriter.WriteCData(strSectionUrl);
                    objWriter.WriteEndElement();

                    objWriter.WriteStartElement("chvFullURL");
                    objWriter.WriteCData(strArticleUrl);
                    objWriter.WriteEndElement();

                    objWriter.WriteEndElement();


                    #endregion 生成XML
                }
            }
        }
    }
}